package com.filmbooks.presenter.movie;

import com.filmbooks.contract.detail.MovieDeatilContract;
import com.filmbooks.model.MovieDetailModel;
import com.filmbooks.model.home.bean.movie.MovieDetailBean;
import com.filmbooks.model.home.bean.movie.PersonBean;
import com.filmbooks.model.home.bean.movie.SubjectsBean;

import io.reactivex.functions.Consumer;

/**
 * Created by heshuxiang on 2018/3/9.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/9.
 * 工程：FilmBooks
 * 包：com.filmbooks.adapter
 */

public class MovieDeatilPresenter extends MovieDeatilContract.MovieDetailPresenter {
    @Override
    public MovieDeatilContract.IMovieDetailModel getModel() {
        return MovieDetailModel.newInstance();
    }

    public static MovieDeatilPresenter newInstance() {
        return new MovieDeatilPresenter();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadMovieDetail(String id) {
        if (mIView == null || mIModel == null)
            return;
       /* mRxManager.register(mIModel.getMovieDetail(id).subscribe(
                new Consumer<MovieDetailBean>() {
                    @Override
                    public void accept(MovieDetailBean movieDetailBean) throws Exception {
                        if (mIView == null)
                            return;
                        mIView.showMovieDetail(movieDetailBean);
                    }

                }), new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView == null)
                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError();
            }
        });*/
        mRxManager.register(mIModel.getMovieDetail(id).subscribe(new Consumer<MovieDetailBean>() {
            @Override
            public void accept(MovieDetailBean bean) throws Exception {
                if (mIView == null)
                    return;

                mIView.showMovieDetail(bean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView == null)
                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError();
            }
        }));
    }

    @Override
    public void onItemClick(int position, PersonBean item) {

    }

    @Override
    public void onHeaderClick(SubjectsBean bean) {

    }
}
